<?php
function tf_common_template_content_section($aContents) {
  $string = '
<section>
<div id="td-center"' . $aContents['selector_td_center'] . '>
';
  $string .= $aContents['body'];
  $string .= '
</div>
</section>
';

  return $string;
}

function tf_common_template_layout($thisTemplate, $aContents) {
  global $thfr_css;

  $output_string = '<!-- wrapper start --><div id="wrapper"';
  if ($thfr_css[$thisTemplate]['uniquewidth'] != '') {
    $output_string .= ' style="width:' . $thfr_css[$thisTemplate]['uniquewidth'] . '"';
  }
  $output_string .= '>
  <!-- container start --><div id="container"' . $aContents['selector_container'] . '>';

  $output_string .= '<!-- content start -->' . $aContents['content'] . '<!-- content end -->';

  if ($thfr_css[$thisTemplate]['uniquewidth'] == '' && $thfr_css['layout-width-type'] != 'fixed') {
    $output_string .= '</div><!-- container end -->';
  }

  $output_string .= '<!-- left start -->' . $aContents['left'] . '<!-- left end -->';
  $output_string .= '<!-- right start -->' . $aContents['right'] . '<!-- right end -->';

  if ($thfr_css[$thisTemplate]['uniquewidth'] != '' || $thfr_css['layout-width-type'] == 'fixed') {
    $output_string .= '<div class="clear"></div>
    </div><!-- container end -->';
  }

  $output_string .= '<!-- header start -->' . $aContents['header'] . '<!-- header end -->';
  $output_string .= '<!-- footer start -->' . $aContents['footer'] . '<!-- footer end -->';

  $output_string .= '</div><!-- wrapper end -->';

  return $output_string;
}

function tf_common_template_header_section($aContents) {
  $string = '<header><div id="td-header"' . $aContents['selector_td_header'] . '>';
  $string .= $aContents['body'];
  $string .= '</div></header>';

  return $string;
}

function tf_common_template_footer_section($aContents) {
  $string = '<footer><div id="td-footer"' . $aContents['selector_td_footer'] . '>';
  $string .= $aContents['body'];
  $string .= '</div></footer>';

  return $string;
}

function tf_common_template_left_section($aContents) {
  if (isset($aContents['sidebarsleft']) && $aContents['sidebarsleft'] == 0) {
    return '';
  }

  $sidebar_left3 = '
  <div class="col-left" id="td-left3"' . $aContents['selector_td_left3'] . '>
  <div id="div-left3"' . $aContents['selector_div_left3'] . '>' . $aContents['sidebar_left3'] . '</div>
  </div>';

  $sidebar_left1 = '<div class="col-left-left" id="td-left1"' . $aContents['selector_td_left1'] . '>
  <div id="div-left1"' . $aContents['selector_div_left1'] . '>' . $aContents['sidebar_left1'] . '</div>
  </div>';

  $sidebar_left2 = '
  <div class="col-left-right" id="td-left2"' . $aContents['selector_td_left2'] . '>
  <div id="div-left2"' . $aContents['selector_div_left2'] . '>' . $aContents['sidebar_left2'] . '</div>
  </div>';

  $string = '<aside>';
  $string .= '<div id="td-left"' . $aContents['td_left_style'] . $aContents['selector_td_left'] . '>';
  $string .= $aContents['drop_area_beforeSidebarLeft'];
  if (!isset($aContents['sidebarsleft']) || $aContents['sidebarsleft'] == 3) {
    $string .= $sidebar_left3;
  }
  $string .= $sidebar_left1;
  if (!isset($aContents['sidebarsleft']) || $aContents['sidebarsleft'] > 1) {
    $string .= $sidebar_left2;
  }
  $string .= $aContents['drop_area_afterSidebarLeft'];
  $string .= '</div>';
  $string .= '</aside>';
  return $string;
}

function tf_common_template_right_section($aContents) {
  if (isset($aContents['sidebarsright']) && $aContents['sidebarsright'] == 0) {
    return '';
  }

  $sidebar_right3 = '
  <div class="col-right" id="td-right3"' . $aContents['selector_td_right3'] . '>
  <div id="div-right3"' . $aContents['selector_div_right3'] . '>' . $aContents['sidebar_right3'] . '</div>
  </div>';

  $sidebar_right1 = '<div class="col-right-right" id="td-right1"' . $aContents['selector_td_right1'] . '>
  <div id="div-right1"' . $aContents['selector_div_right1'] . '>' . $aContents['sidebar_right1'] . '</div>
  </div>';

  $sidebar_right2 = '
  <div class="col-right-left" id="td-right2"' . $aContents['selector_td_right2'] . '>
  <div id="div-right2"' . $aContents['selector_div_right2'] . '>' . $aContents['sidebar_right2'] . '</div>
  </div>';

  $string = '<aside>';
  $string .= '<div id="td-right"' . $aContents['td_right_style'] . $aContents['selector_td_right'] . '>';
  $string .= $aContents['drop_area_beforeSidebarRight'];
  if (!isset($aContents['sidebarsright']) || $aContents['sidebarsright'] == 3) {
    $string .= $sidebar_right3;
  }
  if (!isset($aContents['sidebarsright']) || $aContents['sidebarsright'] > 1) {
    $string .= $sidebar_right2;
  }
  $string .= $sidebar_right1;
  $string .= $aContents['drop_area_afterSidebarRight'];
  $string .= '</div>';
  $string .= '</aside>';
  return $string;
}

function tf_common_template_postcontainer_section($aContents) {
  $string = '<!-- Post Start --><div' . $aContents['post_class'] . $aContents['post_id'] . $aContents['post_selector'] . '>';

  $string .= $aContents['drop_area_beforePost'];

  if ($aContents['kickercheck'] == 'on') {
    $string .= '%thumbpos-2%' . "\n";
    $string .= '<div class="post-kicker"' . $aContents['kicker_selector'] . '>' . $aContents['kickercode'] . '</div>' . "\n";
  }

  $string .= $aContents['drop_area_beforePostTitle'];
  if ($aContents['headlinecheck'] == 'on') {
    $string .= '%thumbpos-3%' . "\n";
    $string .= '<header><div class="post-headline"' . $aContents['headline_selector'] . '>' . $aContents['headlinecode'] . '</div></header>' . "\n";
  }

  if ($aContents['bylinecheck'] == 'on') {
    $string .= '%thumbpos-4%' . "\n";
    $string .= '<div class="post-byline"' . $aContents['byline_selector'] . '>' . $aContents['bylinecode'] . '</div>' . "\n";
  }
  $string .= $aContents['drop_area_afterPostTitle'];

  if ($aContents['contentcheck'] == 'on') {
    $string .= '%thumbpos-5%' . "\n";
    $string .= '<div' . $aContents['content_class'] . $aContents['content_selector'] . '>' . "\n";

    $string .= '%thumbpos-6%' . "\n";

    if ($aContents['contenttype'] == 'excerpt') {
      $string .= $aContents['the_excerpt'] . "\n";
    } else {
      $string .= $aContents['thecontent'] . "\n";
      $string .= $aContents['linkpages'] . "\n";
    }
    $string .= '%thumbpos-7%';
    $string .= '</div>' . "\n";
    $string .= '%thumbpos-8%' . "\n";
  }

  if ($aContents['footercheck'] == 'on') {
    $string .= '<footer><div class="post-footer"' . $aContents['footer_selector'] . '>' . $aContents['footercode'] . '</div></footer>' . "\n";
    $string .= '%thumbpos-9%';
  }

  $string .= $aContents['drop_area_afterPost'];

  $string .= '</div><!-- Post End -->' . "\n";

  return $string;
}

?>